package com.huangkailong.designpattern.composite.safe;

import java.util.ArrayList;
import java.util.List;

/**
 * 文件夹.
 *
 * @author huangkl
 * @since 1.0.0
 */
public class Folder implements FileInfo {
    private final String path;
    private final List<FileInfo> fileInfos;

    public Folder(String path) {
        this.path = path;
        this.fileInfos = new ArrayList<>();
    }

    @Override
    public String getPath() {
        return path;
    }

    @Override
    public void showInfo(int level) {
        for (int i = 0; i < level; i++) {
            System.out.print("\t");
        }
        System.out.println(path);
        for (FileInfo fileInfo : fileInfos) {
            fileInfo.showInfo(level + 1);
        }
    }

    /**
     * 添加文件信息.
     *
     * @param fileInfo {@link FileInfo}
     * @return true 添加成功, false 添加失败
     */
    public boolean addFileInfo(FileInfo fileInfo) {
        return fileInfos.add(fileInfo);
    }

    /**
     * 移除文件信息.
     *
     * @param fileInfo {@link FileInfo}
     * @return ture 移除成功, false 移除失败
     */
    public boolean removeFileInfo(FileInfo fileInfo) {
        return fileInfos.remove(fileInfo);
    }
}
